package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class MenuItemTag extends BodyTagSupport{
	
	private String customClassItem;
	private String customTextClassItem;
	private String hrefItem;
	private String valueItem;
	private boolean disabledItem;
	
	@Override
	public int doEndTag() throws JspException {
		
		JspWriter saida = pageContext.getOut();
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();		
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("customClassItem", customClassItem);
		request.setAttribute("customTextClassItem", customTextClassItem);
		request.setAttribute("hrefItem", hrefItem);
		request.setAttribute("valueItem", valueItem);
		request.setAttribute("disabledItem", disabledItem);
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/menuItem.jsp");
		
		try {
			
			req.include(request, responseWrapper);
			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);
			
		}catch(IOException io){
			
			io.printStackTrace();
			
		} catch (ServletException s) {
			
			s.printStackTrace();
		}
		
		return super.doEndTag();
	}

	public String getCustomClassItem() {
		return customClassItem;
	}

	public void setCustomClassItem(String customClassItem) {
		this.customClassItem = customClassItem;
	}

	public String getCustomTextClassItem() {
		return customTextClassItem;
	}

	public void setCustomTextClassItem(String customTextClassItem) {
		this.customTextClassItem = customTextClassItem;
	}

	public String getHrefItem() {
		return hrefItem;
	}

	public void setHrefItem(String hrefItem) {
		this.hrefItem = hrefItem;
	}

	public String getValueItem() {
		return valueItem;
	}

	public void setValueItem(String valueItem) {
		this.valueItem = valueItem;
	}

	public boolean isDisabledItem() {
		return disabledItem;
	}

	public void setDisabledItem(boolean disabledItem) {
		this.disabledItem = disabledItem;
	}
	
}
